package com.example.blood_sugar.adapters;

import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;

import com.example.blood_sugar.R;

import java.util.List;

/**
 * 血糖曲线图中未TabLayout适配fragment的适配器
 */
public class BloodSugarChartFragmentAdapter extends FragmentPagerAdapter {

    // TabLayout的标题list
    private List<String> list;
    // 要适配的fragment LIst
    private List<Fragment> mFragments;

    /**
     * 构造方法
     * @param fm
     * @param list
     * @param fragments
     */
    public BloodSugarChartFragmentAdapter(FragmentManager fm, List<String> list, List<Fragment> fragments) {
        super(fm);
        this.list = list;
        mFragments = fragments;
    }

    /**
     * 重写通过position获取fragment的方法
     * @param position
     * @return
     */
    @Override
    public Fragment getItem(int position) {
//        if (position == 0)
//            return BloodSugarChartFragment24Hours.newInstance(list.get(position));
//        return BloodSugarChartFragment7days.newInstance(list.get(position));
        return mFragments.get(position);
    }

    /**
     * 获取count
     * @return
     */
    @Override
    public int getCount() {
        return list.size();
    }

    /**
     * 通过position获取标题
     * @param position
     * @return
     */
    @Override
    public CharSequence getPageTitle(int position) {
//        String str = list.get(position);
//        SpannableString spannableString = new SpannableString(str);
//        ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#3be7bf"));
//        spannableString.setSpan(colorSpan, 0, str.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        return list.get(position);
    }
}